import { ContentTypeEnum } from '@/enums/httpEnum';
import { defHttp } from '@/utils/http/axios';
import {
  CreateDictionaryParams,
  UpdateDictionaryParams,
  DictionaryListParams,
  DictionaryListGetResultModel,
  CreateDictionaryConfigParams,
  UpdateDictionaryConfigParams,
} from './model/systemModel';

enum Api {
  Dictionary = '/dic/',
  List = '/dic/list',
  DictionaryConfig = '/dic/config/',
  DictionaryUpdateConfig = '/dic/config/update/',
}

/**
 * 创建字典
 * @param params CreateDictionaryParams
 * @returns Promise
 */
export const addDictionary = (params?: CreateDictionaryParams) =>
  defHttp.post(
    {
      url: Api.Dictionary,
      params,
      headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
    },
    { isTransformResponse: false },
  );

/**
 * 更新字典
 * @param params UpdateDictionaryParams
 * @returns Promise
 */
export const updateDictionary = (id: Number, params?: UpdateDictionaryParams) =>
  defHttp.post(
    {
      url: `${Api.Dictionary}${id}`,
      params,
      headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
    },
    { isTransformResponse: false },
  );

/**
 * 字典列表
 * @param params
 * @returns
 */
export const getDictionaryList = (params?: DictionaryListParams) =>
  defHttp.get<DictionaryListGetResultModel>({ url: Api.List, params });

/**
 * 删除字典
 * @param id
 * @returns Promise
 */
export const deleteById = (id: Number) =>
  defHttp.delete(
    {
      url: `${Api.Dictionary}${id}`,
      headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
    },
    { isTransformResponse: false },
  );

/**
 * 添加字典配置
 * @param params CreateDictionaryConfigParams
 * @returns Promise
 */
export const addDictionaryConfig = (id: Number, params?: CreateDictionaryConfigParams) =>
  defHttp.post(
    {
      url: `${Api.DictionaryConfig}${id}`,
      params,
      headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
    },
    { isTransformResponse: false },
  );

/**
 * 更新字典配置
 * @param params UpdateDictionaryConfigParams
 * @returns Promise
 */
export const updateDictionaryConfig = (id: Number, params?: UpdateDictionaryConfigParams) =>
  defHttp.post(
    {
      url: `${Api.DictionaryUpdateConfig}${id}`,
      params,
      headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
    },
    { isTransformResponse: false },
  );
